﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace E1_eMart.admin
{
    public partial class comment_detail : System.Web.UI.Page
    {
        protected Comment cm = new Comment();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["idcm"] != null)
            {               
                int id = int.Parse(Request.Params["idcm"]);
                DataClasses1DataContext edata = new DataClasses1DataContext();
                try
                {
                    cm = edata.Comments.Single<Comment>(c => c.MaComment == id);
                    if (!this.IsPostBack)
                        TextBox1.Text = cm.NoiDungComment;
                }
                catch (Exception ex)
                {
                    Response.Redirect("comment_management.aspx");
                }
            }
        }

        // Save
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Request.Params["idcm"] != null)
            {
                int id = int.Parse(Request.Params["idcm"]);
                DataClasses1DataContext edata = new DataClasses1DataContext();
                cm = edata.Comments.Single<Comment>(c => c.MaComment == id);
                cm.NoiDungComment = TextBox1.Text;
                edata.SubmitChanges();
                Response.Redirect("comment_management.aspx");
            }
        }

        // Delete
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (Request.Params["idcm"] != null)
            {
                int id = int.Parse(Request.Params["idcm"]);
                DataClasses1DataContext edata = new DataClasses1DataContext();
                cm = edata.Comments.Single<Comment>(c => c.MaComment == id);
                edata.Comments.DeleteOnSubmit(cm);
                edata.SubmitChanges();
                Response.Redirect("comment_management.aspx");
            }
        }
    }
}